package com.xueyi.aixihu.controller;

import com.xueyi.aixihu.controller.base.BaseController;
import com.xueyi.aixihu.entity.po.DtNewsSort;
import com.xueyi.aixihu.entity.vo.*;
import com.xueyi.aixihu.exception.SzException;
import com.xueyi.aixihu.reqeust.FindReportFormListReq;
import com.xueyi.aixihu.reqeust.PublishReportFormReq;
import com.xueyi.aixihu.reqeust.UploadReportFormsReq;
import com.xueyi.aixihu.reqeust.UploadVoucherReq;
import com.xueyi.aixihu.response.base.BaseResponse;
import com.xueyi.aixihu.service.ReportFormsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author hxs
 * @createDate 2023/6/28 11:38
 * @description 上传报表相关接口
 */
@RestController
public class ReportFormsController extends BaseController {

    @Autowired
    private ReportFormsService reportFormsService;

    /**
     * 上传报表
     *
     * @return 响应成功
     */
    @RequestMapping("/report/forms/uploadReportForms")
    public BaseResponse<Boolean> uploadReportForms(@Validated UploadReportFormsReq uploadReportFormsReq) throws IOException, SzException {
        reportFormsService.uploadReportForms(uploadReportFormsReq);
        return BaseResponse.success(Boolean.TRUE);
    }

    /**
     * 查询财务报表类型列表
     *
     * @return 财务报表类型列表
     */
    @RequestMapping("/report/forms/findCwTypeList")
    public BaseResponse<List<BaseSelectVo>> findCwTypeList(Integer addressType) throws SzException {
        List<BaseSelectVo> list = reportFormsService.findCwTypeList(addressType);
        return BaseResponse.success(list);
    }

    /**
     * 查询地区列表
     */
    @RequestMapping("/report/forms/findAddressList")
    public BaseResponse<List<DtNewsSort>> findAddressList() {
        return BaseResponse.success(reportFormsService.findAddressList());
    }

    /**
     * 查询报表列表
     *
     * @param findReportFormListReq 查询参数
     * @return 列表
     */
    @RequestMapping("/report/forms/findReportFormList")
    public BaseResponse<DataList<AxhFinanceVo>> findReportFormList(@Validated FindReportFormListReq findReportFormListReq) throws SzException {
        DataList<AxhFinanceVo> flag = reportFormsService.findReportFormList(findReportFormListReq);
        return BaseResponse.success(flag);
    }

    /**
     * 删除报表
     *
     * @param id 报表id
     * @return 响应成功
     */
    @RequestMapping("/report/forms/deleteReportForm")
    public BaseResponse<Boolean> deleteReportForm(Integer id) throws SzException {
        reportFormsService.deleteReportForm(id);
        return BaseResponse.success(Boolean.TRUE);
    }

    /**
     * 发起审核
     *
     * @param id 报表id
     * @return 响应成功
     */
    @RequestMapping("/report/forms/initiateAudit")
    public BaseResponse<Boolean> initiateAudit(Integer id) throws SzException {
        reportFormsService.initiateAudit(id);
        return BaseResponse.success(Boolean.TRUE);
    }

    /**
     * 公开报表
     *
     * @param publishReportFormReq 审核记录
     * @return 响应成功
     */
    @RequestMapping("/report/forms/publishReportForm")
    public BaseResponse<Boolean> publishReportForm(@Validated PublishReportFormReq publishReportFormReq) throws SzException {
        reportFormsService.publishReportForm(publishReportFormReq);
        return BaseResponse.success(Boolean.TRUE);
    }


    /**
     * 获取财务公开各种状态报表的数量
     *
     * @return 对象
     */
    @RequestMapping("/report/forms/findReportFormsSize")
    public BaseResponse<FindReportFormsSizeVo> findReportFormsSize(Integer reportType) throws SzException {
        FindReportFormsSizeVo flag = reportFormsService.findReportFormsSize(reportType);
        return BaseResponse.success(flag);
    }

    /**
     * 操作凭证
     *
     * @param uploadVoucherReq 参数
     * @return 响应成功
     */
    @RequestMapping("/report/forms/uploadVoucher")
    public BaseResponse<Boolean> uploadVoucher(@Validated UploadVoucherReq uploadVoucherReq) throws SzException {
        reportFormsService.uploadVoucher(uploadVoucherReq);
        return BaseResponse.success(Boolean.TRUE);
    }

}
